<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sitemesh" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<div class="panel_container">

    <div class="panel">
        <form id="form_search">
            <div class="panel_header">
                <div><h2>机构管理</h2></div>
            </div>

            <div class="panel_body">
                <div>
                    <div class="info_item"><span>机构名称:</span><input type="text" name="orgName" id="orgName"></div>
                    <div class="info_item"><span>14位银行代码:</span><input type="text" name="orgCode" id="orgCode"></div>
                </div>
            </div>

            <div class="panel_footer">
                <div>
                    <div class="info_item ml_1">
                        <input type="button" value="查询" class="btn_blue" id="btn_search">&nbsp;
                        <input id="createEntity" type="button" class="btn_blue"  value="创建机构">
                    </div>
                </div>
            </div>
        </form>
    </div>

    <div class="panel">
        <div class="panel_body">
            <div>
                <table id="grid_tbl"></table>
                <div id="pager"></div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    function gotoOrgCreatePage(){
        linkTo("${ctx}/system/organization/initEdit");
    }

    function gotoOrgModifyPage(_id){
        linkTo("${ctx}/system/organization/initEdit?id="+_id);
    }

    function gotoOrgViewPage(_id){
        linkTo("${ctx}/system/organization/initEdit?mode=v&id="+_id);
    }

    function deleteOrg(_id){
        $.confirm(function(){
            $.ajax({
                url: "${ctx}/system/organization/delOrg",
                data: {"id": _id},
                success: function (data) {
                    refreshOrgsList();
                }
            });
        })
    }

    function refreshOrgsList(){
        $("#grid_tbl").jqGrid('setGridParam',{postData:$("#form_search").serializeObject()}).trigger("reloadGrid");
    }

    $(function () {
        $("#createEntity").bind("click", function(){
            gotoOrgCreatePage();
        });

        $("#btn_search").bind("click", function(){
            refreshOrgsList();
        });

        $("#grid_tbl").jqGrid({
            datatype: "json",
            url : "${ctx}/system/organization/queryOrgs",
			mtype: "POST",
            width:"100%",
            height:"100%",
            colNames: ['操作','14位银行代码','机构名称','联系电话',  '详细地址'],
            colModel: [
                {name:'act',index:'id',search:false,sortable:false,editable:false
                    ,formatter:function(cellvalue, options, rowObject){ return tagLinkEdit("gotoOrgModifyPage("+rowObject.id+")")+" "+tagLinkDel("deleteOrg("+rowObject.id+")");}
                },
                {name: 'orgCode', index: 'orgCode',sortable:false},
                {name: 'orgName', index: 'orgName',sortable:false
                    ,formatter:function(cellvalue, options, rowObject){ return tagLink("gotoOrgViewPage("+rowObject.id+")",cellvalue);}
                },
                {name: 'telphone', index: 'telphone',sortable:false},
                {name: 'locationAddress', index: 'locationAddress',sortable:false}
            ],
            rowNum: 10,
            rowList:[10,20,30],
            pager: '#pager',
            imgpath: 'images',
            sortname: 'id',
            viewrecords: true,
            sortorder: "desc",
            autowidth:true,
            jsonReader: {
                repeatitems : false,
                id: "id"
            },
            caption: "机构查询结果列表"
        });

    });

</script>